<template>
  <div class="upload-photo">
    <div class="text">
    <span>
  寻找丢失的TA
   </span>
    </div>
    <div class="upload">
      <el-upload
          action="#" list-type="picture-card"
          :auto-upload="false"
          :file-list="fileList"
      >
        <el-icon>
          <Plus/>
        </el-icon>

        <template #file="{ file }">
          <div class="photo-icon" v-if="dialogVisible">
            <img class="el-upload-list__item-thumbnail" :src="file.url" alt=""/>
            <span class="el-upload-list__item-actions">
          <span
              class="el-upload-list__item-preview"
              @click="handlePictureCardPreview(file)"
          >
            <el-icon><zoom-in/></el-icon>
          </span>
          <span
              v-if="!disabled"
              class="el-upload-list__item-delete"
              @click="handleDownload(file)"
          >
            <el-icon><Download/></el-icon>
          </span>
          <span
              v-if="!disabled"
              class="el-upload-list__item-delete"
              @click="handleRemove(file)"
          >
            <el-icon><Delete/></el-icon>
          </span>
        </span>
          </div>
        </template>
      </el-upload>

    </div>
    <div class="Btn">
      <el-button @click="">
        upload to server
      </el-button>
    </div>
  </div>
</template>
<script lang="ts" setup>
//这里上传照片的时候，想把这个文件的东西保存到fileList中再传过去，但是还没有找到方法！！
import {ref} from 'vue'
import {ElMessage} from 'element-plus'
import {Delete, Download, Plus, ZoomIn} from '@element-plus/icons-vue'
import type {UploadFile} from 'element-plus'
import type {UploadProps} from 'element-plus'

const dialogImageUrl = ref('')
const dialogVisible = ref(true)
const disabled = ref(false)
const fileList = ref([])
/**
 * 点击垃圾桶则可以将显示在页面上的照片让他不显示
 * @param file
 */
const handleRemove = (file: UploadFile) => {

  dialogVisible.value = false
  console.log("file.name=" + file.name)
  console.log("file.raw=" + file.raw)
  console.log("file.url=" + file.url)
}
/**
 * 点击放大镜可以让照片放大
 * @param file
 */
const handlePictureCardPreview = (file: UploadFile) => {
  dialogImageUrl.value = file.url!
  dialogVisible.value = true
}

const handleDownload = (file: UploadFile) => {
  console.log(file)
}
</script>
<style scoped>
/**
上传照片的大小
 */

.text span {
  font-size: 20px;
  margin: 0 20px 0 20px;
}
</style>

<style>
.upload-photo {

  margin: 50px 300px 300px 300px;

}

.text {
  margin-left: 150px;
  margin-bottom: 30px;
}

.upload {
  width: 500px;
  height: auto;
  border: #9a9898 solid 1px;
}

.Btn {
  float: right;
  margin-right: 50px;
  margin-top: 50px;
}

.Btn .el-button {
  background-color: #a7d5f1;
}

.photo-icon {
  align-items: center;
}
</style>